package android.contest.ui;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.contest.R;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class WelcomeView extends Activity{
	private ImageView welcomeImg;
	private TextView startMsg, welcomeMsg, tipMsg;
	private int startMsg_color = Color.WHITE;
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Intent intent =  new Intent(this, TaskListView.class);
		startActivity(intent);
		return super.onTouchEvent(event);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_view); 
        
        welcomeImg = (ImageView) findViewById(R.id.welcomeImg);
        welcomeImg.setImageResource(R.drawable.icon);

        welcomeMsg = (TextView) findViewById(R.id.welcomeMsg1);
        welcomeMsg.setText(getResources().getString(R.string.welcome_msg1));
        welcomeMsg = (TextView) findViewById(R.id.welcomeMsg2);
        welcomeMsg.setText(getResources().getString(R.string.welcome_msg2));

        tipMsg = (TextView) findViewById(R.id.tipMsg);
        tipMsg.setText(getResources().getString(R.string.tip_msg));
        
        startMsg = (TextView) findViewById(R.id.startMsg);
        startMsg.setText(getResources().getString(R.string.start_msg));
        spark(startMsg, startMsg_color);
	}
    
    private void spark(TextView tv_msg, int tv_color){
    	class ColorChangeTask extends TimerTask{
    		private int colorCnt = 0;
    		private TextView msg;
    		private int color;
    		
			public ColorChangeTask(TextView msg, int color){
    			this.msg = msg;
    			this.color = color;
    		}
			@Override
			public void run() {
    			runOnUiThread(new Runnable(){
    				public void run(){
    					if(colorCnt == 0){
    						colorCnt = 1;
    						msg.setTextColor(Color.TRANSPARENT);
    					}else if (colorCnt == 1){
    						colorCnt = 0;
    						msg.setTextColor(color);
    					}
    				}
    			});				
			}    		
    	}
    	Timer timer = new Timer();
    	ColorChangeTask cct = new ColorChangeTask(tv_msg, tv_color);
    	timer.schedule(cct, 1, 500);    	
    }
    
    public class CalenderAdapter extends BaseAdapter {
        private Context mContext;

        public CalenderAdapter(Context c) {
            mContext = c;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            TextView calenderCell;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                calenderCell = new TextView(mContext);
                calenderCell.setLayoutParams(new GridView.LayoutParams(45, 45));
                calenderCell.setPadding(5, 5, 5, 5);
                if(position >= 29)
                {
                	calenderCell.setBackgroundColor(Color.GRAY);
                }
                else
                {
                	calenderCell.setBackgroundColor(Color.MAGENTA);
                }
                calenderCell.setText(((Integer)(position + 1)).toString());
                //System.out.println(position);
            } else {
                calenderCell = (TextView) convertView;
            }
            return calenderCell;
        }

		public int getCount() {
			return 31;
		}

    }
}
